﻿using CPF;
using CPF.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPFUI.IControl
{
    public class MindNode : CpfObject
    {
        public MindNode()
        {
            NextNode = new Collection<MindNode> ();
        }
        /// <summary>
        /// 下一个节点结合
        /// </summary>
        public Collection<MindNode> NextNode
        {
            get { return GetValue<Collection<MindNode>>(); }
            set { SetValue(value); }
        }
        /// <summary>
        /// 名称说明
        /// </summary>
        public string Caption
        {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }
        public MindNodeOrientation Orientation
        {
            get { return GetValue<MindNodeOrientation>(); }
            set { SetValue(value); }
        }
        /// <summary>
        /// 大小
        /// </summary>
        public SizeField Size { 
            get { return GetValue<SizeField>(); }
            set { SetValue(value); }
        }

        /// <summary>
        /// 位置
        /// </summary>
        public Point Location
        {
            get { return GetValue<Point>(); }
            set { SetValue(value); }
        }
        public Point GetStartConnectPoint()
        {
            Point p= new Point();
            Rect rec=new Rect();
            switch (Orientation)
            {
                case MindNodeOrientation.Right:
                    rec = LeftRect();
                    break;
                case MindNodeOrientation.Left:
                    rec = RightRect();
                    break;
                case MindNodeOrientation.Bottom:
                    rec = TopRect();
                    break;
                case MindNodeOrientation.Top:
                    rec = BottomRect();
                    break;
            }
            p = new Point(rec.X + 3, rec.Y + 3);
            return p;
        }
        public Point GetStartConnectPointForNextNode(MindNodeOrientation orientation)
        {
            Point p = new Point();
            Rect rec = new Rect();
            switch (orientation)
            {
                case MindNodeOrientation.Left:
                    rec = LeftRect();
                    break;
                case MindNodeOrientation.Right:
                    rec = RightRect();
                    break;
                case MindNodeOrientation.Top:
                    rec = TopRect();
                    break;
                case MindNodeOrientation.Bottom:
                    rec = BottomRect();
                    break;
            }
            p = new Point(rec.X + 3, rec.Y + 3);
            return p;
        }
        public Rect LeftRect (){
            return  new Rect(Left - 3, Top + Size.Height.Value / 2 - 3, 6, 6);
        }
        public Rect TopRect()
        {
            return new Rect(Left + Size.Width.Value / 2 - 3, Top - 3, 6, 6);
        }
        public Rect RightRect()
        {
            return new Rect(Left + Size.Width.Value - 3, Top + Size.Height.Value / 2 - 3, 6, 6);
        }
        public Rect BottomRect()
        {
            return new Rect(Left + Size.Width.Value / 2 - 3, Top + Size.Height.Value - 3, 6, 6);
        }
        public float Left
        {
            get { return GetValue<float>(); }
            set { SetValue(value); }
        }
        public float Top
        {
            get { return GetValue<float>(); }
            set { SetValue(value); }
        }
        /// <summary>
        /// 节点图形
        /// </summary>
        public MindNodeGraphType GraphType
        {
            get { return GetValue<MindNodeGraphType>(); }
            set { SetValue(value); }
        }
        /// <summary>
        /// 数据
        /// </summary>
        public object Data
        {
            get { return GetValue<object>(); }
            set { SetValue(value); }
        }
    }
}
